package com.tz.dao.impl;

import com.tz.dao.IGroupDao;
import com.tz.entity.Group;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2016/8/5.
 */
@Repository

public class GroupDaoImpl implements IGroupDao {

    @Autowired
    private SessionFactory sessionFactory;

    private Session getSession() {
        return sessionFactory.getCurrentSession();
    }

    @Override
    @Transactional
    public List<Group> findAllGroup() {
        return getSession().createQuery("from com.tz.entity.Group").list();
    }

    @Override
    @Transactional
    public void save(Group group) {
        getSession().save(group);
    }
}
